import msgs
import time

class log:
	def __init__(self, logFile):
		try:
			self.fd = open(logFile, 'w')
		except:
			print msgs.E_LOG_ERROR
			exit(1)

	def write(self, data, normal):
		if normal:
			data = "%s%s : %s %s\r\n" % (msgs.L_NORMAL, str(time.asctime()), str(data), msgs.L_ENDC)
		else:
			data = "%s%s %s %s\r\n" % (msgs.L_WARNING, str(time.asctime()), str(data), msgs.L_ENDC)
		self.fd.write(data)	
		self.fd.flush()

	def close(self):
		self.fd.close()
